package com.bit.leetcode;

import java.util.LinkedHashMap;
import java.util.Map;

public class day_1026 {
    //剑指offer60.n个筛子的点数
    class Solution {
        public double[] dicesProbability(int n) {
            int[][] dp = new int[n+1][6*n+1];
            for(int i = 1;i<=6;++i){
                dp[1][i] = 1;
            }
            for(int i = 2;i<=n;++i){
                for(int j = i;j<=6*i;++j){
                    for(int k = 1;k<=6&&j>=k;++k){
                        dp[i][j] += dp[i-1][j-k];
                    }
                }
            }
            double[] res = new double[6*n-n+1];
            for(int i = n;i<=6*n;++i){
                res[i-n] = ((double)dp[n][i])/Math.pow(6,n);
            }
            return res;
        }
    }
    //剑指offer50.第一次出现的字符
    class Solution1 {
        public char firstUniqChar(String s) {
            Map<Character,Boolean> map = new LinkedHashMap<>();
            char[] ch= s.toCharArray();
            for(char c:ch){
                map.put(c,!map.containsKey(c));
            }
            for(Map.Entry<Character,Boolean> entry:map.entrySet()){
                if(entry.getValue())  return entry.getKey();
            }
            return ' ';
        }
    }

}
